package com.api.client.imp;

import java.util.HashMap;
import java.util.Map;

import org.scribe.model.OAuthRequest;

import com.api.client.Method;
import com.api.client.Request;
import com.api.client.Response;
import com.app.AppContext;

public class RequestImp implements Request{

	private static OAuthSigner signer = AppContext.getBean(OAuthSigner.class);
	
	private OAuthRequest request;
	
	RequestImp(OAuthRequest request){
		
		this.request = request;
	}

	public Response send() {
		
		return new ResponseImp(request.send());
	}

	public Response sendSigned(String accessKey, String accessSecret) {

		signer.sign(request, accessKey, accessSecret);
		
		return send();
	}
	
	public Method getMethod(){
		
		return Method.valueOf(request.getVerb().toString());
	}
	
	public String getUrl(){
		return request.getUrl();
	}

	public Map<String, String> getQueryParams() {
		return request.getQueryStringParams();
	}

	public Map<String, String> getBodyParams() {
		return request.getBodyParams();
	}

	public Map<String, String> getHeaders() {
		
		Map<String, String> headers = new HashMap<String, String>();
		
		headers.putAll(request.getHeaders());
		
		headers.putAll(request.getOauthParameters());
	
		return headers;
	}
}
